import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import requests
def analysis(filename,name,list_type,list_degree):
   plt.close()
   plt.style.use('seaborn-dark')
   plt.rcParams['font.sans-serif']=['STHeiti']
   df = pd.read_excel(filename)

   df=df[df['学员姓名']==name].T.iloc[11:21]
   df.columns=['本题得分']
   df['题型']=list_type
   df['难度']=list_degree
   df['本题得分']=df['本题得分'].astype(int)
   df['本题失分']=10-df['本题得分']
   df1=df.groupby('难度').agg('sum')
   df1=df1.reindex(['简单','中等','困难'])
   plt.subplot(121)
   plt.title('根据难易程度分析')

   plt.bar(df1.index,df1['本题得分'],label='本题得分')
   plt.bar(df1.index,df1['本题失分'],label='本题失分',bottom=df1['本题得分'])
   plt.legend() 
   #
   df2=df.groupby('题型').agg('sum')
   plt.subplot(122)
   plt.title('根据知识分类分析')
   plt.bar(df2.index,df2['本题得分'],label='本题得分')
   plt.bar(df2.index,df1['本题失分'],label='本题失分',bottom=df2['本题得分'])
   plt.legend() 
   name=name.replace(r'/','')
   plt.savefig('./output/'+name+".jpeg",dpi = 600)



def get_done_list(name):
   df= pd.read_excel(name)
   return list(df[df['第1题']!='未提交']['学员姓名'])




if __name__ == '__main__':
   # filename='作业批改详情 (1).xlsx'
   # type=['直线运动','竖直上抛','牛顿定律','牛顿定律','牛顿定律','牛顿定律','竖直上抛','竖直上抛','竖直上抛','直线运动']
   # degree=['简单','简单','中等','简单','中等','简单','中等','困难','困难','困难']
   # #analysis(filename,'邱元',type,degree)
   # for i in get_done_list(filename):
   #    analysis(filename,str(i),type,degree)
   #    1
   #商品ID
   id="7618131"
   cookie="client_type=android;app_id=161;login_mode=2;jxjpin=jd_5034sgd449;tgt=AAJdpH2tAECIq9Iyj66E4LRaAI24c22YcteFi3lGSASGQ236AAzFmbD33b_PmXl0gRTqBGASEvv35wEx1Z9ve7vUTej0vvN2Z;qwd_chn=99;qwd_schn=1"
   cookie="client_type=android;app_id=161;login_mode=2;jxjpin=liuweijiang;tgt=AAJeRLFOAEDrvns7Wa5X5p56env8GSam33DZgrTwcg4vFqgkYVi6vQreW4jXKBAjr-EFZhDR49rM68e_4bI2TyOWGiKY0En8;qwd_chn=99;qwd_schn=1"
   cookie="client_type=android;app_id=161;login_mode=2;jxjpin=13138881311_p;tgt=AAJe1ScIAECBg69L5kmLsMwTeyGt4GQjGCw6iOYwRgGAUFFInxinRlBF8hiDeYz8E0zEeVINRmud9antTjew4TYRKwglDSjQ;qwd_chn=99;qwd_schn=1"
   cookies={}#初始化cookies字典变量
   for line in cookie.split(';'):   #按照字符：进行划分读取
      #其设置为1就会把字符串拆分成2份
      name,value=line.strip().split('=',1)
      cookies[name]=value
   url="https://qwd.jd.com/cps/zl?content=https%3A//item.jd.com/" + id + ".html&shareSource=1_2_1"
   url="https://api.m.jd.com/api?functionId=ConvertSuperLink"
   print(url)
   r = requests.get(url,cookies=cookies)
   print(r)   
   r = requests.post(url,cookies=cookies)
   print(r)

   #str ＝ 网页_访问S (“https://api.jingpinjd.com/open/?api=get_goods_link&appid=” ＋ appid ＋ “&sign=” ＋ sign ＋ “&union_id=” ＋ JDunionid ＋ “&position_id=” ＋ JDpositionid ＋ “&material_url=” ＋ 编码_URL编码 (url, 真, 真), , , , , , , , , , , , , , , , , , , , )